package com.info.zhiduoduo.repository.mapper.crowdsource;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.crowdsource.OddJobRechargeRecordDetailDto;
import com.info.zhiduoduo.repository.entity.crowdsource.OddJobRechargeRecord;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
 * @author tianyonghong
 * @create 2023/2/23
 */
public interface OddJobRechargeRecordMapper extends BaseMapper<OddJobRechargeRecord> {

    @Select(" select ojrr.*,ccp.company_name as rechargePartyName,ojm.merchant_name as merchantName" +
            " from zdd_odd_job_recharge_record ojrr " +
            " left join zdd_crowdsource_company_party ccp on ojrr.recharge_party_id=ccp.id" +
            " left join zdd_odd_job_merchant ojm on ojrr.merchant_id=ojm.merchant_id" +
            " where ojrr.is_del = 0 " +
            " and ojrr.id = #{id}")
    List<OddJobRechargeRecordDetailDto> selectDetail(Integer id);

    @Select(" select ojrr.*,ccp.company_name as rechargePartyName,ojm.merchant_name as merchantName" +
            " from zdd_odd_job_recharge_record ojrr " +
            " left join zdd_crowdsource_company_party ccp on ojrr.recharge_party_id=ccp.id" +
            " left join zdd_odd_job_merchant ojm on ojrr.merchant_id=ojm.merchant_id" +
            " where ojrr.is_del = 0" +
            " and IF(ISNULL(#{merchantId}) or #{merchantId} = 0,1=1, ojm.merchant_id = #{merchantId}) " +
            " and IF(ISNULL(#{state}),1=1,ojrr.state=#{state})" +
            " and IF(ISNULL(#{startTime}) or #{startTime} = '',1=1, ojrr.create_time >= #{startTime}) " +
            " and IF(ISNULL(#{endTime}) or #{endTime} = '',1=1, ojrr.create_time <= #{endTime}) " +
            " order by ojrr.id desc ")
    List<OddJobRechargeRecordDetailDto> selectList(Integer merchantId, Integer state, Date startTime, Date endTime);
}
